/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.game.entity.enemy;

import ace.game.Sprite;
import ace.game.entity.bullet.BulletData;
import ace.system.Utilities;
import ace.system.xml.XmlNode;

/**
 *
 * @author Hallucinogen
 */
public class EnemyData  {
	protected EnemyData() {
		mScore			= 0;
		mVelocity		= 0;
		mHealthMax		= 1;

		mSprites	= null;
	}

	public EnemyData(XmlNode xml) {
		//Initialize
		this();

		//Prepare variable

		//For each node
		for(int i=0; i < xml.getChildren().size(); ++i) {
			//Get tag name and it's value
            XmlNode Node    = (XmlNode)xml.getChildren().elementAt(i);
			String Tag		= Node.getNodeName();
			String Value	= ((XmlNode)Node.getChildren().elementAt(0)).getNodeValue();

			//Save data
			if(Tag.equals("score"))                 mScore           = Integer.parseInt(Value);
			else if (Tag.equals("velocity"))        mVelocity       = Float.parseFloat(Value);
			else if (Tag.equals("sprite"))          mImageNode      = (XmlNode)xml.getChildren().elementAt(i);
            else if (Tag.equals("health"))          mHealthMax      = Integer.parseInt(Value);
			else if (Tag.equals("body-size"))       mBodySize       = Integer.parseInt(Value);
			else if (Tag.equals("explosion-color"))	mExplosionColor	= Integer.parseInt(Value, 16);
            else if (Tag.equals("seeking"))         mSeeking		= Integer.parseInt(Value) == 1;
            else if (Tag.equals("weapon")) {
                for (int j = 0, m = Node.getChildren().size(); j < m; ++j) {
                    XmlNode CNode   = (XmlNode)Node.getChildren().elementAt(j);
                    String CTag     = CNode.getNodeName();
                    String CValue   = ((XmlNode)CNode.getChildren().elementAt(0)).getNodeValue();

                    if (CTag.equals("reload"))                  mReloadTime		= Integer.parseInt(CValue);
                    else if (CTag.equals("bullet"))             mBulletData		= new BulletData(CNode);
                    else if (CTag.equals("split"))              mSplitCount		= Integer.parseInt(CValue);
                    else if (CTag.equals("spread"))             mSpreadCount	= Integer.parseInt(CValue);
                    else if (CTag.equals("bullet-per-wave"))    mBulletPerWave	= Integer.parseInt(CValue);
                    else if (CTag.equals("wave-reload"))        mWaveReload     = Integer.parseInt(CValue);
                }
            }
        }

        // TODO: delay creating sprite
		//Create sprite
		if (mImageNode != null) {
			mSprites = new Sprite(mImageNode, Utilities.ENEMY_FOLDER);
		}
	}

	public int getScore()               { return mScore;            }
	public int getHealthMax()           { return mHealthMax;        }
	public float getVelocity()          { return mVelocity;         }
	public Sprite getSprite()           { return mSprites;          }
	public int getBodySize()            { return mBodySize;         }
    public int getExplosionColor()      { return mExplosionColor;   }
    public int  getReloadTime()         { return mReloadTime;       }
    public BulletData getBulletData()   { return mBulletData;       }
    public int getSplitCount()          { return mSplitCount;       }
    public int getSpreadCount()         { return mSpreadCount;      }
    public int getBulletPerWave()       { return mBulletPerWave;    }
    public int getWaveReload()          { return mWaveReload;       }
    public boolean isSeeking()          { return mSeeking;          }

    // data
	protected int		mScore;
    protected int		mHealthMax;
	protected float		mVelocity;
    protected int       mBodySize;
    protected int       mExplosionColor;
    protected boolean   mSeeking;

	//Images
	protected Sprite mSprites;
    protected XmlNode mImageNode;

    // enemy shooting stuffs
    private int mReloadTime;
    private BulletData mBulletData;
    private int mSplitCount;
    private int mSpreadCount;
    private int mBulletPerWave;
    private int mWaveReload;
}
